import { TeaDefine } from "../../../kds-base-define/src/TeaDefine";
import { DB } from "../db";

function getKey(teaID:number,userID:number) {
	return "tea=" + teaID + "|user=" + userID
}
let redis = DB.redis
let tableName = "t_tea_useraccount"
async function setUserAccount(h:string,teaID:number,userID:number,account:TeaDefine.TeaUserAccount) {
	await redis.hset(tableName,getKey(teaID,userID),account,true)
	return true
}

async function getUserAccount(h:string,teaID:number,userID:number) {
	let ret:TeaDefine.TeaUserAccount = await redis.hget(tableName,getKey(teaID,userID),true)
	return ret 
}

async function removeUserAccount(h:string,teaID:number,userID:number) {
	await redis.hdel(tableName,getKey(teaID,userID))
	return true 
}

export let RpcTeaUserAccount = {
	set:setUserAccount,
	get:getUserAccount,
	remove:removeUserAccount,
}